﻿namespace EyeOpen.Extensions
{
    using System;
    using System.Linq.Expressions;

    /// <summary>
    /// Contains extension methods for Expression.
    /// </summary>
    public static class ExpressionExtensions
    {
        /// <summary>
        /// Gets the name of the property.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="expression">The expression.</param>
        /// <returns></returns>
        public static string GetPropertyName<T>(this Expression<Func<T, object>> expression)
        {
            var memberExpression = expression.Body as MemberExpression;
            var member = memberExpression.Member;
            return member.Name;
        }
    }
}
